package sim;

import java.awt.Color;
import java.awt.Graphics2D;

public class Food {

	private static final double initialArea = 200;
	private double area;
	private double radius;
	private Vec2 position;
	
	public Food(Vec2 position)
	{
		this.position = position;
		area = initialArea;
		radius = getRadius(area);
	
	}
//    public void collisionWallFood(Vec2 upperLeft,Vec2 lowerRight)
//    {
//        if((getPosition().x-radius) <upperLeft.x)
//        {
//        	setPosition(new Vec2(upperLeft.x+radius, getPosition().y));
//        }
//        if((getPosition().y-radius) <upperLeft.y)
//        {
//        	setPosition(new Vec2(getPosition().x, upperLeft.y+radius));
//        }
//        if((getPosition().y+radius) >lowerRight.y)
//        {
//        	setPosition(new Vec2(getPosition().x, lowerRight.y-radius));
//        }
//        if((getPosition().x+radius)>lowerRight.x)
//        {
//        	setPosition(new Vec2(lowerRight.x-radius, getPosition().y));
//        }        
//    }
	
	public void draw(Graphics2D g2d)
    {
		g2d.setColor(new Color(0,200,0));
        g2d.fillOval((int)(getPosition().GetX()-radius), (int)(getPosition().GetY()-radius), (int)(2*radius), (int)(2*radius));
    }
	
	public Vec2 getPosition() {
		return position;
	}
	
	public void decreaseArea(double areaEaten)
	{
		//shrink the food blob as it is being eaten - subtract amount eaten, and decrease area
		area -=areaEaten;
		radius = Math.sqrt(area/Math.PI);		
	}
	
	public void setPosition(Vec2 position) {
		this.position = position;
	}
	public double getRadius(double area) 
	{
		radius = Math.sqrt(area/Math.PI);
		return radius;
	}
	public double getRadius() {
		return radius;
	}

	public double getArea() {
		return area;
	}
}
